package com.zxjbyte.yiyi.server.domain.request.demo;

import com.zxjbyte.yiyi.framework.common.enums.SortOrder;
import com.zxjbyte.yiyi.framework.common.annotation.InEnumValue;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * 演示复杂结构嵌套validation校验用法
 *
 * @Author zhangxingjia
 * @Date 2023/3/1 19:14
 * @Version: 1.0
 */
@Getter
@Setter
@Schema(description = "postValid请求结构体")
public class DemoPostValidRequest {

    @Schema(description = "id")
    @NotNull(message = "id不能为空")
    private Long id;

    @Schema(description = "名字")
    @NotBlank(message = "请填写名字")
    private String name;

    @Schema(description = "obj")
    private Object obj;

    @Schema(description = "map")
    private Map<String, Object> map;

    @Schema(description = "枚举值验证")
    @NotBlank(message = "枚举值验证不能为空")
    @InEnumValue(enumClass = SortOrder.class, ignoreCase = true)
    private String sortOrder;

    @Schema(description = "模拟嵌套校验")
    @Valid
    @NotEmpty(message = "人属性不能为空")
    private List<Person> personList;

    @Data
    @Schema(description = "Person请求结构体")
    public static class Person{

        @Schema(description = "id")
        @NotNull(message = "年龄不能为空")
        private Long age;

        @Schema(description = "名字")
        @NotBlank(message = "请填写地址")
        private String address;

        @Schema(description = "邮箱")
        private String mail;

        @Schema(description = "私人汽车")
        @Valid
        private Car car;

        @Schema(description = "子结构")
        @Valid
        private List<Person> childList;
    }

    @Data
    @Schema(description = "Car请求结构体")
    public static class Car{

        @Schema(description = "汽车颜色")
        @NotBlank(message = "请填写汽车颜色")
        private String color;

        @Schema(description = "车轮数量")
        private Integer wheelNumber;
    }
}
